package com.alibaba.controller;

import com.alibaba.entity.User;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author: zhuangzhiwen
 * @Date: 2021/8/21
 */

@Component
public class BeanInit implements InstantiationAwareBeanPostProcessor {
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
        if ("user".equals(beanName)){
            System.out.println("实例化之前");
        }
        return null;
    }


    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
        if("userService".equals(beanName)){
            System.out.println("实例化之后");
        }
        return true;
    }
}
